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
	LD	A," "
	RST	#10
	LD	A,8
	RST	#10
	JR	READLN1
;
TXBLOCK
	DI
	LD	HL,#C000
	LD	B,16
T1
	LD	A,#33
	OUT	(#F7),A
	XOR	A
	CALL	TXBYTE
	DJNZ	T1
;
TXBLOCK1
	LD	A,#33
	OUT	(#F7),A
	LD	A,(HL)
	CALL	TXBYTE
	INC	HL
	CP	#1A
	JR	NZ,TXBLOCK1
	CALL	TXBYTE
	CALL	TXBYTE
	CALL	TXBYTE
	CALL	TXBYTE
	CALL	TXBYTE
	CALL	TXBYTE
	CALL	TXBYTE
	EI
	RET
;
TXBYTE
	PUSH	AF
TXBYTE1
	CALL	#1F54
	JR	NC,BREAK
	IN	A,(#F7)
	BIT	0,A
	JR	Z,TXBYTE1
	POP	AF
	OUT	(#77),A
	RET
GETKBD
	EI
	RES	5,(IY+1)
GETKBD1
	BIT	5,(IY+1)
	JR	Z,GETKBD1
	CALL	#1F54
	JP	NC,BREAK
	LD	A,(IY-50)
	RES	5,(IY+1)
	RET
;
EOF

